package com.huiminpay.merchant.service;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.huiminpay.common.cache.util.RandomUuidUtil;
import com.huiminpay.merchant.convert.StaffConvert;
import com.huiminpay.merchant.entity.Staff;
import com.huiminpay.merchant.mapper.StaffMapper;
import com.yh.merchant.api.Service.IStaffService;
import com.yh.merchant.api.dto.StaffDTO;
import org.apache.dubbo.config.annotation.Service;

import org.springframework.beans.factory.annotation.Autowired;

/**
 * @ClassName : StaffService
 * @Author : 阿泽
 * @Date: 2021/8/16 16:28
 * @Description :
 */
@Service
public class StaffServiceImpl implements IStaffService {
    @Autowired
    StaffMapper staffMapper;
    @Override
    public StaffDTO createStaff(StaffDTO staffDTO) {
        //非空校验
        //对象转换
        Staff staff = StaffConvert.INSTANCE.dto2Entity(staffDTO);
        //员工id需要自己生成
        staff.setId(Long.valueOf(RandomUuidUtil.getUUID()));
        staffMapper.insert(staff);

        return StaffConvert.INSTANCE.entity2Dto(staff);
    }

    @Override
    public String delStaff(Long id) {
        staffMapper.deleteById(id);
        return "删除成功";
    }

    @Override
    public String updateStaff(StaffDTO staffDTO) {
        staffMapper.updateById(StaffConvert.INSTANCE.dto2Entity(staffDTO));
        return "更新成功";
    }
}
